//confirmorder.js

Page({
  data: {
    peimode: '0',
    shorTage: false,
    index: 0,
    array: ['中骏店', '万达店', '百汇店'],
    goodsShow: true,
    paycode: true,
    payword: true,
    pwdVal: '', //输入的密码
    payFocus: true, //文本框焦点
    storepickupTime: "",
    shippingFeeInfo: [
      "订单金额满XXX元起，配送费XX元",
      "订单满200元，免费配送"
    ],
    singlechoiceArr: [
      '钱包余额（10.00元）',
      '支付宝',
      '微信',
    ]
  },
  onLoad: function() {
    let that = this;

  },
  distributionMode: function(e) {
    let that = this;
    that.setData({
      peimode: e.currentTarget.dataset.id
    })
  },
  chooseAddress: function() {
    wx.navigateTo({
      url: '/pages/address/address?status=1'
    })
  },
  appointmentMode: function(e) {
    console.log(e)
    let that = this;
    that.setData({
      index: e.detail.value
    })
  },
  orderCoupon: function() {
    wx.navigateTo({
      url: '/packageA/pages/ordercoupon/ordercoupon'
    })
  },
  // finishHandler: function (e) {
  //       console.log(e.detail)
  // },
  placeOrder: function() {
    let that = this;
    // that.setData({
    //     goodsShow: false
    // }, () => {
    //     let animation = wx.createAnimation({
    //         duration: 600,
    //         timingFunction: 'ease'
    //     })
    //      that.animation = animation 
    //      setTimeout(function(){
    //        that.fadeIn();
    //     },300)
    // })
    wx.requestPayment({
      timeStamp: '1570851693',
      nonceStr: '98b0c56ac4a4488194b789a68ff5aec0',
      package: 'prepay_id=wx121141336120446b60e8b8c11737616700',
      signType: 'RSA',
      paySign: 'BpyvsIwD/2OL0oDJlPmSxlubzSum1GPflLdm5Pxb3DPVdf2+LknOOvcETcyGmLF1Ew1+o7eVT52+5A2mQ+tt2WFVooxzmVlflTRuu9yjrp3tcUYWyl/mMhaOYHqeDZX+rwC2rr1qczJsdojZpwxVrvJO1plgAo/E2lueKutslMjzVT8Uab507Y/oPKKE5XGYFuWkpxnxZ1eonQH9IseOdJXNoHvsdgi/hkVV/3K+a0Hv+zDI39SL7ryZ4crdM3NLKX3iSaSTDxqZ3rXzVIdpdtTKjgmIEaaFy5r12iDBCOmzPLuYsRdcwKaw+l90IXeC1c/XcitiBsn48WT+yikgaA==',
      success(res) {},
      fail(res) {}
    })
  },
  closeGoodsLayer: function() {
    let that = this;
    that.setData({
      goodsShow: true,
      payword: true
    }, () => {
      let animation = wx.createAnimation({
        duration: 600,
        timingFunction: 'ease'
      })
      that.animation = animation
      setTimeout(function() {
        that.fadeOut();
      }, 300)
    })
  },
  fadeIn: function() {
    let that = this;
    that.animation.translateY(0).step()
    that.setData({
      animationData: that.animation.export()
    })
  },
  fadeOut: function() {
    let that = this;
    that.animation.translateY(360).step()
    that.setData({
      animationData: that.animation.export()
    })
  },
  nowPay: function() {
    let that = this;
    let judge = that.data.paycode;
    if (judge) {
      that.setData({
        payword: false
      })
    } else {
      that.setData({
        goodsShow: true
      }, () => {
        wx.showModal({
          title: '提示',
          content: '您还没有设置支付密码,请点击去设置!',
          cancelColor: '#999999',
          confirmColor: '#ff0028',
          confirmText: '去设置',
          success(res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/packageA/pages/setpassword/setpassword'
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      })
    }
  },
  /**
   * 获取焦点
   */
  getFocus: function() {
    let that = this;
    that.setData({
      payFocus: true
    });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function(e) {
    let that = this;
    that.setData({
      pwdVal: e.detail.value
    });
    if (e.detail.value.length >= 6) {
      wx.showToast({
        title: '支付成功',
        icon: 'success',
        duration: 1500,
        success: function() {
          that.setData({
            goodsShow: true,
            payword: true,
            pwdVal: ''
          }, () => {
            let animation = wx.createAnimation({
              duration: 600,
              timingFunction: 'ease'
            })
            that.animation = animation
            setTimeout(function() {
              that.fadeOut();
            }, 300)
          })
        }
      })
    }
  },
  // 获取到店自提选择时间
  getPickUpTime(e) {
    console.log(e.detail)
    if (e.detail) {
      this.setData({
        storepickupTime: e.detail.date === "立即自提" ? e.detail.date : e.detail.day.time + ' ' + e.detail.date
      })
    } else {
      
    }
  },
  // 自提时间选择
  selectPickUpTime() {
    this.selectComponent('#storepickup').showModel();
  },
  getWay() {
    this.selectComponent('#singlechoice').showModel();
  },
  shippingFee() {
    this.selectComponent('#message').orderLogistics();
  }
})